// .eslintrc.js
import { defineConfig } from "eslint/config";
import js from "@eslint/js";
import globals from "globals";
import pluginVue from "eslint-plugin-vue";
import pluginPrettier from "eslint-plugin-prettier";
import pluginTaro from "eslint-plugin-taro";

const vueFiles = ["**/*.{js,mjs,cjs,vue}"];
export default defineConfig([
  // JS 基础规则（ESLint 推荐）
  {
    files: vueFiles,
    ...js.configs.recommended,
    languageOptions: {
      globals: globals.browser,
    },
  },

  // Vue 插件基础配置（支持 Vue 单文件组件）
  ...pluginVue.configs["flat/essential"],

  // Taro 插件配置（启用官方推荐规则）
  {
    files: vueFiles,
    plugins: {
      taro: pluginTaro,
    },
    rules: pluginTaro.configs.all.rules,
  },

  // Prettier 集成配置
  {
    files: vueFiles,
    plugins: {
      prettier: pluginPrettier,
    },
    rules: {
      "prettier/prettier": "error",
    },
  },

  // 自定义规则覆盖
  {
    rules: {
      "no-console": "off",
      "vue/multi-word-component-names": "warn", // 允许单单词组件名
      "no-unused-vars": "warn",
      "no-undef": "warn",
    },
  },
]);